import {
	createApp
} from 'vue'
import Cookies from 'js-cookie'
const app = createApp(App)

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	app.component(key, component)
}
import locale from 'element-plus/es/locale/lang/zh-cn'

import App from './App'
import store from './store'
import router from './router'

import "./assets/reset.css";
import "./assets/my.css";
import "./assets/customIcon.css"


// 进度条
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
NProgress.configure({
	showSpinner: false
});
//指令
import directive from './directive' // directive
directive(app)
//引入所有组件
const files = import.meta.glob('./components/**/*.vue');
for (const path in files) {
	const name = path.split('/').pop()?.split('.')[0]
	app.component(name, defineAsyncComponent(files[path]));
}

//引入所有工具类-暂未解决，eager报错
// const utilFiles = import.meta.glob('./utils/*.js', { eager: true });
// for (const path in utilFiles) {
// 	const name = path.split('/').pop()?.split('.')[0]
// 	app.config.globalProperties['$' + name] = utilFiles[path]
// }
//引入api
import api from "./api/api.js"
app.config.globalProperties.$api = api
import common from "./utils/common.js"
app.config.globalProperties.$common = common
import http from "./utils/http.js"
app.config.globalProperties.$http = http

// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
	locale: locale,
	// 支持 large、default、small
	size: Cookies.get('size') || 'default',
	zIndex: 3000
})
import sys from './store/modules/sys.js'
import dict from './store/modules/dict.js'
import tagsView from './store/modules/tagsView.js'
app.config.globalProperties.$store = {
	sys,
	dict,
	tagsView
}

app.use(router)
app.use(store)

// 字典数据组件
import dictdata from '@/use/dictdata'
dictdata.install(app)

//Highlight.js代码语法高亮显示
//引入依赖和语言
import 'highlight.js/styles/stackoverflow-light.css'
import hljs from "highlight.js/lib/core";
import hljsVuePlugin from "@highlightjs/vue-plugin";

//import "highlight.js/lib/common"; //单一加载
//按需引入语言
import javascript from "highlight.js/lib/languages/javascript";
import java from "highlight.js/lib/languages/java";
import sql from "highlight.js/lib/languages/sql";
import xml from "highlight.js/lib/languages/xml";
import html from "highlight.js/lib/languages/vbscript-html";
import json from "highlight.js/lib/languages/json";
import yaml from "highlight.js/lib/languages/json";
hljs.registerLanguage("java", java);
hljs.registerLanguage("xml", xml);
hljs.registerLanguage("html", html);
hljs.registerLanguage("vue", xml);
hljs.registerLanguage("javascript", javascript);
hljs.registerLanguage("sql", sql);
hljs.registerLanguage("yaml", yaml);
hljs.registerLanguage("json", json);
app.use(hljsVuePlugin)

app.mount('#app')